package Client;

import java.awt.BorderLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.List;
import javax.swing.JFrame;

import javax.sound.sampled.AudioSystem;

import javax.sound.sampled.*;
//import javax.sound.sampled.;

import GameState.Map.Wind;
import GameState.Projectiles.CannonBall;
import GameState.Ships.PirateShip;
import GameState.GameState;
import Server.GameServer;
import Server.Player;


public class GameClient extends JFrame{


	/**
	 * The crap default Id.
	 */
	private static final long serialVersionUID = 1L;
	private GamePanel myScreen;
	private AudioSystem myBackgroundPlayer;
	private final Player mYOU;
	private Clip soundClip;



	public GameClient(final GameServer theGame) throws IOException{

		intiFullScreen();

		mYOU = new Player();

		//creates the screen objects TODO fix rendering thing
		myScreen = new GamePanel(this, this.getWidth(), this.getHeight());

		this.add(myScreen, BorderLayout.CENTER);

		new Thread(myScreen).start();
		this.pack();
		this.setVisible(true);
		//		this.invalidate();
		//		this.repaint(1000L);


	}

	private void createBackgroundMusic(){

		//soundClip =
		//soundClip.start();
		//soundClip.

		//AudioSystem.getClip(mixerInfo); 
		/*
			//make a new AudioPlayer.
			myBackgroundPlayer = AudioPlayer.player;
			AudioStream  myBackgroundMusic;
			ContinuousAudioDataStream myLoop = null;
			//use a try block in case the file doesnt exist.
			try {
				myBackgroundMusic = new AudioStream(new FileInputStream("pirateMusic.mid"));

				AudioData myStream =  myBackgroundMusic.getData();

				myLoop = new ContinuousAudioDataStream(myStream);



			}
			catch(IOException error) {

				error.printStackTrace();

			}


			if(myLoop != null){
				// play background music.
				myBackgroundPlayer.start(myLoop);
			}*/

	}




	/**
	 * Create the full screen mode
	 */
	private void intiFullScreen(){

		GraphicsDevice gd;

		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();


		gd = ge.getDefaultScreenDevice();


		this.setUndecorated(true);
		this.setIgnoreRepaint(true);// have to first get rendering to the screen to work out correctly first
		this.setResizable(false);

		if(!gd.isFullScreenSupported()){

			System.exit(0);

		}
		gd.setFullScreenWindow(this);

		/*
		 * Have to get the bound of the screen later to match it up correctly.
		 */




	}


	public void closeClient(){

		//		try {
		//myShips.remove(myShip);
		//		} catch (RemoteException e) {
		//			e.printStackTrace();
		//		} // causes the players ship to dissapare.
		System.exit(0);

	}

	public void requestForward(){


	}

	public void requestLeft(){


	}



	public void requestRight(){


	}


	public void requestShootLeft(){

	}
	public void requestShootRight(){


	}
	public void requestAnchor(){

	}


	public Player getPlayer(){

		return mYOU;

	}






}